﻿package com.designoutput.ui.controls
{
    import com.designoutput.enum.ToolType;
    import com.designoutput.event.ColorPadEvent;
    
    import flash.display.*;
    import flash.geom.*;

    public class ColorPad extends Sprite
    {
        internal var pad:Bitmap;
        internal var half:Boolean;
		public var color:uint;
		private var _alphaVal:Number;
		

        public function ColorPad(defaultColor:uint, half:Boolean = false)
        {
            this.color = defaultColor;
            this.half = half;
            var height:Number = half ? (19) : (29);
            this.graphics.beginFill(9474192);
            this.graphics.drawRect(0, 0, 30, height);
            this.graphics.beginFill(16777215);
            this.graphics.drawRect(1, 1, 28, height - 2);
            this.graphics.endFill();
            this.pad = new Bitmap(new BitmapData(26, height - 4, false, defaultColor));
            this.pad.y = 2;
            this.pad.x = 2;
            addChild(this.pad);
        }

		public function get alphaVal():Number
		{
			return _alphaVal;
		}

		public function set alphaVal(value:Number):void
		{
			_alphaVal = value;
		}

        public function get value() : uint
        {
            return this.color;
        }

        public function set value(color:uint) : void
        {
            this.Set(color);
        }

        public function Set(color:uint, alphaVal:Number=1) : void
        {
            this.color = color;
			this.alphaVal = alphaVal;
            this.pad.bitmapData.fillRect(new Rectangle(0, 0, 26, height - 4), color);
            dispatchEvent(new ColorPadEvent(this.color));
        }
		
		public function setColor(color:uint):void{
			this.color = color;
			this.alphaVal = alphaVal;
			this.pad.bitmapData.fillRect(new Rectangle(0, 0, 26, height - 4), color);
		}

    }
}
